package lab.chapter;

import lombok.NoArgsConstructor;

@NoArgsConstructor
public class GrammarTransition extends Transition {
    // 状态迁移条件
    protected String condition = null;

    public GrammarTransition(String condition) {
        this.condition = condition;
    }

    public GrammarTransition(int maxTimes) {
        this.maxTimes = maxTimes;
    }

    /**
     * 是否满足迁移条件
     * 输入的 GrammarNode 和迁移条件是否相等
     * @param grammarName 节点名
     * @return bool
     */
    public boolean match(String grammarName) {
        if(isEpsilon()) {
            return false;
        }
        return condition.equals(grammarName);
    }

    @Override
    public boolean match(Object object) {
        return match((String) object);
    }

    @Override
    public boolean isEpsilon() {
        return condition == null;
    }

    @Override
    public String toString() {
        if (isEpsilon()) {
            return "ε";
        }
        return condition;
    }
}
